<?php
namespace App\Api\Controllers\V1;

use App\Api\Helper\ReturnMessage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;

class AppController extends BaseController
{
	//获取当前版本
	public function vertion (Request $request) {
		$type = $request->get('type', '');
		$channel = $request->get('channel', 'default');
		$debug = $request->get('debug', 0);
		$versions = config('system.qkw_app_version');
		if (empty($versions[$type])) {
			return ReturnMessage::success('未知app',1002);
		}
		$v = $versions[$type];
		//特殊处理Android
		if ($type == 'android') {
			$channelList = array(
				'default' => 'qike',
				'kuan' => 'kuan',
				'xiaomi' => 'xiaomi',
				'qh360' => 'qh360',
				'pugongying' => 'pugongying',
				'huawei' => 'huawei',
				'anzhi' => 'anzhi',
				'meizu' => 'meizu',
			);
			if (!empty($channelList[$channel])) {
				$channelName = $channelList[$channel];
			} else {
				$channelName = $channelList['default'];
			}
			$filename = "app-".$channelName.($debug == 0 ? "-release.apk" : "-debug.apk");
			$v['url'] = ("http://tmp.qikevip.com/package/android/".$filename);
		}//特殊处理Android end 
		return ReturnMessage::successData($v);
	}
	
	public function audit (Request $request) {
		$type = $request->get('type', '');
		$version = $request->get('v', '');
		if (strtolower($type) != 'ios') {
			return ReturnMessage::success('未知app',10002);
		}
		$auditingV = config('system.qkw_app_version.auditing');
		$result = array('auditing'=>0);
		if ($auditingV == $version) {
			$result['auditing'] = 1;
		}
		return ReturnMessage::successData($result);
	}
}
